package com.artpri.action.user;

import com.artpri.action.BaseAction;
import com.artpri.model.UserInfo;

/**
 * 用户登录
 * @author ZhangSi
 */
public class LoginAction extends BaseAction{

	private static final long serialVersionUID = 1L;

	private String lalias;
	private String luser;
	private String lpass;

	private String redirect;

	private String msg;

	public String login() throws Exception {
		boolean login = getUserService().login(luser, lpass, getSession());
		if (login) {
			UserInfo user = getSessionUser();
			lalias = user.getUserName();
			msg = SUCCESS;
		}
		return login ? SUCCESS : LOGIN;
	}
	
	public String logout() throws Exception {
		getUserService().logout(getSession());
		msg = SUCCESS;
		return SUCCESS;
	}

	public String keepLogin() throws Exception {
		if (getSessionUser() != null) {
			msg = SUCCESS;
			return SUCCESS;
		} else {
			if (getUserService().keepLogin(luser, lpass, getSession())) {
				UserInfo user = getSessionUser();
				lalias = user.getUserName();
				msg = SUCCESS;
				return SUCCESS;
			}
			msg = LOGIN;
			return SUCCESS;
		}
	}
	
	

	public String getRedirect() {
		return redirect;
	}

	public void setRedirect(String redirect) {
		this.redirect = redirect;
	}

	public String getLalias() {
		return lalias;
	}

	public void setLalias(String lalias) {
		this.lalias = lalias;
	}

	public String getLuser() {
		return luser;
	}

	public void setLuser(String luser) {
		this.luser = luser;
	}

	public String getLpass() {
		return lpass;
	}

	public void setLpass(String lpass) {
		this.lpass = lpass;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
